package com.ruoyi.driver.service.impl;

import java.util.List;
import com.ruoyi.common.constant.DriverConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.driver.mapper.TDriverInfoMapper;
import com.ruoyi.driver.domain.TDriverInfo;
import com.ruoyi.driver.service.ITDriverInfoService;

/**
 * 司机信息Service业务层处理
 * 
 * @author wzy
 * @date 2024-10-12 19:29:23
 */
@Service
public class TDriverInfoServiceImpl implements ITDriverInfoService 
{
    @Autowired
    private TDriverInfoMapper tDriverInfoMapper;

    /**
     * 查询司机信息
     * 
     * @param driverId 司机信息主键
     * @return 司机信息
     */
    @Override
    public TDriverInfo selectTDriverInfoByDriverId(Long driverId)
    {
        return tDriverInfoMapper.selectTDriverInfoByDriverId(driverId);
    }

    /**
     * 查询司机信息列表
     * 
     * @param tDriverInfo 司机信息
     * @return 司机信息
     */
    @Override
    public List<TDriverInfo> selectTDriverInfoList(TDriverInfo tDriverInfo)
    {
        return tDriverInfoMapper.selectTDriverInfoList(tDriverInfo);
    }

    /**
     * 新增司机信息
     * 
     * @param tDriverInfo 司机信息
     * @return 结果
     */
    @Override
    public int insertTDriverInfo(TDriverInfo tDriverInfo)
    {
        tDriverInfo.setCreateTime(DateUtils.getNowDate());
        return tDriverInfoMapper.insertTDriverInfo(tDriverInfo);
    }

    /**
     * 修改司机信息
     * 
     * @param tDriverInfo 司机信息
     * @return 结果
     */
    @Override
    public int updateTDriverInfo(TDriverInfo tDriverInfo)
    {
        tDriverInfo.setUpdateTime(DateUtils.getNowDate());
        return tDriverInfoMapper.updateTDriverInfo(tDriverInfo);
    }

    /**
     * 批量删除司机信息
     * 
     * @param driverIds 需要删除的司机信息主键
     * @return 结果
     */
    @Override
    public int deleteTDriverInfoByDriverIds(Long[] driverIds)
    {
        return tDriverInfoMapper.deleteTDriverInfoByDriverIds(driverIds);
    }

    /**
     * 删除司机信息信息
     * 
     * @param driverId 司机信息主键
     * @return 结果
     */
    @Override
    public int deleteTDriverInfoByDriverId(Long driverId)
    {
        return tDriverInfoMapper.deleteTDriverInfoByDriverId(driverId);
    }

    /**
     * 校验身份证是否唯一
     *
     * @param tDriverInfo 客户信息
     * @return 结果
     */
    @Override
    public String checkIdentityCardNumberUnique(TDriverInfo tDriverInfo)
    {
        Long driverId = StringUtils.isNull(tDriverInfo.getDriverId()) ? -1L : tDriverInfo.getDriverId();
        TDriverInfo info = tDriverInfoMapper.checkIdentityCardNumberUnique(tDriverInfo.getIdentityCardNumber());
        if (StringUtils.isNotNull(info) && info.getDriverId().longValue() != driverId.longValue())
        {
            return DriverConstants.NOT_UNIQUE;
        }
        return DriverConstants.UNIQUE;
    }

    /**
     * 校验司机姓名是否唯一
     *
     * @param tDriverInfo 客户信息
     * @return 结果
     */
    @Override
    public String checkDriverNameUnique(TDriverInfo tDriverInfo)
    {
        Long driverId = StringUtils.isNull(tDriverInfo.getDriverId()) ? -1L : tDriverInfo.getDriverId();
        TDriverInfo info = tDriverInfoMapper.checkDriverNameUnique(tDriverInfo.getDriverName());
        if (StringUtils.isNotNull(info) && info.getDriverId().longValue() != driverId.longValue())
        {
            return DriverConstants.NOT_UNIQUE;
        }
        return DriverConstants.UNIQUE;
    }
}
